package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.Floor;
import com.zzyl.nursing.service.IFloorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 楼层Controller
 *
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/elder/floor" )
@Tag(name = "楼层相关接口" )
public class FloorController extends BaseController {
    @Autowired
    private IFloorService floorService;

    /**
     * 查询楼层列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:floor:list')" )
    @GetMapping("/list" )
    @Operation(summary = "查询楼层列表" )
    public TableDataInfo list(Floor floor) {
        startPage();
        List<Floor> list = floorService.selectFloorList(floor);
        return getDataTable(list);
    }

    /**
     * 导出楼层列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:floor:export')" )
    @Log(title = "楼层" , businessType = BusinessType.EXPORT)
    @Operation(summary = "导出楼层列表" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Floor floor) {
        List<Floor> list = floorService.selectFloorList(floor);
        ExcelUtil<Floor> util = new ExcelUtil<Floor>(Floor.class);
        util.exportExcel(response, list, "楼层数据" );
    }

    /**
     * 获取楼层详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:floor:query')" )
    @GetMapping("/{id}" )
    @Operation(summary = "获取楼层详细信息" )
    public R<Floor> getInfo(@Schema(title = "楼层ID" )
                            @PathVariable("id" ) Long id) {
        return R.ok(floorService.selectFloorById(id));
    }

    /**
     * 新增楼层
     */
    @PreAuthorize("@ss.hasPermi('nursing:floor:add')" )
    @Log(title = "楼层" , businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增楼层" )
    public AjaxResult add(@Schema(title = "楼层实体" ) @RequestBody Floor floor) {
        return toAjax(floorService.insertFloor(floor));
    }

    /**
     * 修改楼层
     */
    @PreAuthorize("@ss.hasPermi('nursing:floor:edit')" )
    @Log(title = "楼层" , businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改楼层" )
    public AjaxResult edit(@Schema(title = "楼层实体" ) @RequestBody Floor floor) {
        return toAjax(floorService.updateFloor(floor));
    }

    /**
     * 删除楼层
     */
    @PreAuthorize("@ss.hasPermi('nursing:floor:remove')" )
    @Log(title = "楼层" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @Operation(summary = "删除楼层" )
    public AjaxResult remove(@Schema(title = "楼层ID数组" ) @PathVariable Long[] ids) {
        return toAjax(floorService.deleteFloorByIds(ids));
    }

    /**
     * 根据床位状态查询获取所有楼层数据
     */
    @GetMapping("/getRoomAndBedByBedStatus/{status}" )
    @Operation(summary = "根据床位状态查询获取所有楼层数据" )
    public AjaxResult getAllFloorByStatus(@Schema(title = "床位状态" ) @PathVariable("status" ) Integer status) {
        return AjaxResult.success(floorService.getAllFloorByStatus(status));
    }
}
